package com.hdu.dwh.utils;

import org.springframework.util.MultiValueMap;

import com.hdu.dwh.dtos.UserDto;
import com.hdu.dwh.dtos.user_dtos.RegisterUserDto;
import com.hdu.dwh.pojos.SupersetUser;

public class SupersetUtils {
    /**
     * 将 UserDto 转换为 SupersetUser,构造默认的SupersetUser对象
     * @param userDto
     * @return
     */
    public static SupersetUser convertToSupersetUser(RegisterUserDto userDto) {
        String firstName = userDto.getUsername();
        String lastName = userDto.getUsername();
        String username = userDto.getUsername();
        String email = userDto.getUsername() + "@example.com"; // 默认邮箱
        String password = userDto.getPassword();
        return new SupersetUser(firstName, lastName, username, email, password);
    }

    public static MultiValueMap<String, String> convertToRegisterForm(SupersetUser user) {
        MultiValueMap<String, String> form = new org.springframework.util.LinkedMultiValueMap<>();
        form.add("first_name", user.getFirst_name());
        form.add("last_name", user.getLast_name());
        form.add("username", user.getUsername());
        form.add("active", String.valueOf(user.getActive()));
        form.add("email", user.getEmail());
        form.add("roles", String.valueOf(user.getRoles()));
        form.add("password", user.getPassword());
        form.add("conf_password", user.getConf_password());
        return form;
    }

    public static MultiValueMap<String, String> convertLoginToForm(String username, String password) {
        MultiValueMap<String, String> form = new org.springframework.util.LinkedMultiValueMap<>();
        form.add("username", username);
        form.add("password", password);
        return form;
    }
}
